Skip to content

Replace TemplateContextType.isInContext deprecated method - #528

Closed
juan-mora-google wants to merge 2 commits into
flutter:mainfrom
juan-mora-google:chore/jmora/template-context-type-deprecation
Closed

Replace TemplateContextType.isInContext deprecated method#528
juan-mora-google wants to merge 2 commits into
flutter:mainfrom
juan-mora-google:chore/jmora/template-context-type-deprecation

Conversation

@juan-mora-google

@juan-mora-google juan-mora-google commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description

Replaced deprecated method isInContext from TemplateContextType class in DartTemplateContextType.java file

Testing steps:

1. Run the IDE in Sandbox mode with the plugin
2. Prepare a Live Template for testing
Inside the Sandbox IDE window:

  • Go to the IDE settings (Settings / Preferences).
  • Navigate to Editor > Live Templates.
  • Click the + (Add) button and select Live Template.
  • Give it an abbreviation (e.g., dtest) and some template code (e.g., print('hello');).
  • At the bottom, you will see a red warning saying "No applicable contexts". Click Define.
  • Find Dart option (which matches the contextId registered in the plugin.xml) and check it.
  • Apply.

3. Test the "Happy Path" (It should work)

  • Create a .dart file inside the Sandbox IDE
  • Start typing the abbreviation previously defined (dtest).
  • The IDE should suggest the template. If you press Tab, the code will expand. This confirms that file.getLanguage() instanceof DartLanguage evaluated to true.

4. Test the "Negative Path" (It should not work)

  • Create a file with a different extension in the same project, for example test.java or test.txt.
  • Attempt to type the abbreviation (dtest).
  • The IDE should not suggest or expand the template, since the condition requiring it to be a DartLanguage file is not met.

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

@google-cla

google-cla Bot commented Jul 21, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the isInContext method in DartTemplateContextType to accept a TemplateActionContext parameter instead of PsiFile and offset, aligning with modern IntelliJ Platform APIs. The review feedback correctly points out that the @Override annotation was omitted during this refactoring and should be restored to maintain compile-time safety.

@juan-mora-google
juan-mora-google force-pushed the chore/jmora/template-context-type-deprecation branch from 5c9f552 to ed57493 Compare July 22, 2026 02:54
@cj-radcliff
cj-radcliff requested a review from helin24 July 23, 2026 16:35
@helin24

helin24 commented Jul 23, 2026

Copy link
Copy Markdown
Member

Looks reasonable to me and I see tests are passing!

Can you add to the description how we can manually test that this is working? e.g. what user activity would trigger this code path, what should happen, and what could we expect if this change has broken it? (I'm going to add to our PR template to note that this is relevant for most PRs)

@juan-mora-google

Copy link
Copy Markdown
Contributor Author

Looks reasonable to me and I see tests are passing!

Can you add to the description how we can manually test that this is working? e.g. what user activity would trigger this code path, what should happen, and what could we expect if this change has broken it? (I'm going to add to our PR template to note that this is relevant for most PRs)

These are the steps to repro:
1. Run the IDE in Sandbox mode with the plugin
2. Prepare a Live Template for testing
Inside the Sandbox IDE window:

  • Go to the IDE settings (Settings / Preferences).
  • Navigate to Editor > Live Templates.
  • Click the + (Add) button and select Live Template.
  • Give it an abbreviation (e.g., dtest) and some template code (e.g., print('hello');).
  • At the bottom, you will see a red warning saying "No applicable contexts". Click Define.
  • Find Dart option (which matches the contextId registered in the plugin.xml) and check it.
  • Apply.

3. Test the "Happy Path" (It should work)

  • Create a .dart file inside the Sandbox IDE
  • Start typing the abbreviation previously defined (dtest).
  • The IDE should suggest the template. If you press Tab, the code will expand. This confirms that file.getLanguage() instanceof DartLanguage evaluated to true.

4. Test the "Negative Path" (It should not work)

  • Create a file with a different extension in the same project, for example test.java or test.txt.
  • Attempt to type the abbreviation (dtest).
  • The IDE should not suggest or expand the template, since the condition requiring it to be a DartLanguage file is not met.

@juan-mora-google

Copy link
Copy Markdown
Contributor Author

Closing this PR due to CLA problems

@juan-mora-google
juan-mora-google deleted the chore/jmora/template-context-type-deprecation branch July 28, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants